﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Chinaer.Model.Common;
using Chinaer.Core.Helper;

namespace Chinaer.Bll
{
    public class CustomerLoginDetail : Repository, IBll.ICustomerLoginDetail
    {
        private static CustomerLoginDetail _instance = null;
        public static CustomerLoginDetail Instance
        {
            get
            {
                if (_instance == null)
                {
                    _instance = new CustomerLoginDetail();
                }
                return _instance;
            }
            set
            {
                _instance = value;
            }
        }

        private Chinaer.IDao.ICustomerLoginDetailDAO customerLoginDetailDAO = new Chinaer.Dao.CustomerLoginDetailDAO();
        public JsonResult Add(DTO.CustomerLoginDetailDTO t)
        {
            if (t.CheckIsNull().Success == false)
            {
                return t.CheckIsNull();
            }
            JsonResult jsonResult = new JsonResult();
            Model.Entities.Model_CustomerLoginDetails model_CustomerLoginDetail = new Model.Entities.Model_CustomerLoginDetails();
            Chinaer.Core.Helper.DTOtoEntityObjectHelper.Instance.DTOtoEntityObject(t, model_CustomerLoginDetail);
            if (string.IsNullOrEmpty(model_CustomerLoginDetail.ID) || model_CustomerLoginDetail.ID.Trim() == "")
            {
                model_CustomerLoginDetail.ID = Chinaer.Core.Helper.GenerateIDHelper.GenerateID();
            }
            jsonResult.Success = customerLoginDetailDAO.Add(model_CustomerLoginDetail);
            return jsonResult;
        }

        public JsonResult Delete(DTO.CustomerLoginDetailDTO t)
        {
            if (t.CheckIsNull().Success == false)
            {
                return t.CheckIsNull();
            }
            JsonResult jsonResult = new JsonResult();
            Model.Entities.Model_CustomerLoginDetails model_CustomerLoginDetail = new Model.Entities.Model_CustomerLoginDetails();
            Chinaer.Core.Helper.DTOtoEntityObjectHelper.Instance.DTOtoEntityObject(t, model_CustomerLoginDetail);
            jsonResult.Success = customerLoginDetailDAO.Delete(model_CustomerLoginDetail);
            return jsonResult;
        }

        public JsonResult Delete(string id)
        {
            JsonResult jsonResult = new JsonResult();
            jsonResult.Success = customerLoginDetailDAO.Delete(id);
            return jsonResult;
        }

        public JsonResult Update(DTO.CustomerLoginDetailDTO t)
        {
            if (t.CheckIsNull().Success == false)
            {
                return t.CheckIsNull();
            }
            JsonResult jsonResult = new JsonResult();
            Model.Entities.Model_CustomerLoginDetails model_CustomerLoginDetail = new Model.Entities.Model_CustomerLoginDetails();
            Chinaer.Core.Helper.DTOtoEntityObjectHelper.Instance.DTOtoEntityObject(t, model_CustomerLoginDetail);
            jsonResult.Success = customerLoginDetailDAO.Update(model_CustomerLoginDetail);
            return jsonResult;
        }

        public DTO.CustomerLoginDetailDTO GetByID(string id)
        {
            Model.Entities.Model_CustomerLoginDetails model_CustomerLoginDetail = new Model.Entities.Model_CustomerLoginDetails();
            DTO.CustomerLoginDetailDTO customerLoginDetailDTO = new DTO.CustomerLoginDetailDTO();
            model_CustomerLoginDetail = customerLoginDetailDAO.GetByID(id);
            Chinaer.Core.Helper.DTOtoEntityObjectHelper.Instance.DTOtoEntityObject(model_CustomerLoginDetail, customerLoginDetailDTO);
            return customerLoginDetailDTO;
        }
    }
}
